home *** CD-ROM | disk | FTP | other *** search
Text File | 1999-03-04 | 4.3 KB | 183 lines | [TEXT/ToyS] |
- -- Properties
- property kasName : "Copy Folder V1.0"
- property kasSrc : path to system folder as alias -- "Source:topfolder:"
- property kasDst : ""
-
- -- Globals
- global gasFoldersToDo -- The folders left to process
- global gasDestFold -- Current destination
- global gasDestTop -- kasDst & name of kasSrc
- global gwdInfo -- Info window
-
-
- on run
- set kasDst to ":" as alias
- open {kasSrc} -- Default to kasSrc
- end run
-
-
- on open fsObjs
- InfoNew()
-
- -- Start up stuff
- set gasFoldersToDo to {}
- -- Our destination folder named as the source folder
- set srcName to ":" & (original name of (alias info from kasSrc)) & ":"
- set gasDestTop to verify path srcName relative to kasDst
- set gasDestFold to gasDestTop -- Single items to this folder
-
- -- Separate files from folders
- repeat with fsObj in fsObjs
- set myInfo to (basic info for fsObj)
-
- if (catalog kind of myInfo is a folder) then
- PushFolder(fsObj)
- else
- if not DoOne(fsObj) then ShowErrorItem(catalog name of myInfo)
- end if
- end repeat
-
- -- Do folders
- repeat while gasFoldersToDo is not {}
- GoDeep(PopFolder())
- end repeat
-
- InfoDel()
- end open
-
-
- on DoOne(fsObj)
- -- display dialog "Src:" & fsObj & return & "Dst:" & gasDestFold
- try
- AkuaCopy fsObj to gasDestFold with overwriting
- return true
- on error errStr number errNum
- ShowError(errStr, errNum)
- return false
- end try
- end DoOne
-
-
- on GoDeep(foldObj)
- set daddy to foldObj as string
- ShowPath(daddy)
-
- -- Create our subfolder in destination
- set srcPath to kasSrc as string
- -- Subtract that from front of daddy
- set subPath to the text from character (length of srcPath) to -1 of daddy
- -- Create the path in the destination
- set gasDestFold to verify path subPath relative to gasDestTop
-
- -- Queue folders
- set myItems to the entries in foldObj ¬
- whose kinds are a folder
- repeat with myItem in myItems
- PushFolder((daddy & myItem) as alias)
- end repeat
-
- -- Do files
- set myItems to the entries in foldObj ¬
- whose kinds are a file
- -- If you don't want to copy aliases, comment out the following line
- set myItems to myItems & (the entries in foldObj ¬
- whose kinds are an alias)
-
- set n to (the number of items in myItems)
-
- if (n > 0) then
- if (n > 10) then
- -- Progress window for folders w/ more than 10 items
- set itemPg to display progress titled ("Folder Copy") ¬
- subtitled (catalog name of (basic info for foldObj)) ¬
- maximum n
- else
- set itemPg to 0
- end if
-
- repeat with myItem in myItems
- if (itemPg is not 0) then ¬
- if canceled of (display progress itemPg labeled myItem value 0) then ¬
- display dialog "Continue with the rest?"
- ShowItem(myItem)
- if not DoOne((daddy & myItem) as string) then ShowErrItem(myItem)
- end repeat
-
- if (itemPg is not 0) then ¬
- display progress itemPg with disposal
- end if
- end GoDeep
-
-
- on PushFolder(foldAli)
- set gasFoldersToDo to gasFoldersToDo & {foldAli}
- ShowFolderCnt(number of items of gasFoldersToDo)
- end PushFolder
-
-
- on PopFolder()
- -- Pop one off the front
- copy item 1 of gasFoldersToDo to fsObj
- set gasFoldersToDo to edit list gasFoldersToDo with edits {-1}
- ShowFolderCnt(number of items of gasFoldersToDo)
- return fsObj
- end PopFolder
-
-
- on ShowPath(fsPath)
- display info gwdInfo ¬
- message ("Path: " & fsPath)
- end ShowPath
-
-
- on ShowItem(fsName)
- display info gwdInfo ¬
- message ("File: " & fsName) at line 2
- end ShowItem
-
-
- on ShowError(errStr, errNum)
- display info gwdInfo ¬
- message ("Error: " & errStr & " (" & errNum & ")") at line 3 ¬
- using bg color (30 * 1024) + (25 * 32) + 25
- -- User canceled?
- if (errNum is -128) then display dialog ("Continue?")
- end ShowError
-
-
- on ShowErrItem(fsName)
- display info gwdInfo ¬
- message ("…copying " & fsName) at line 4 ¬
- using bg color (30 * 1024) + (25 * 32) + 25
- beep
- pause for 120
- if (option key down of (input state)) then display dialog ("Continue?")
- end ShowErrItem
-
-
- on ShowFolderCnt(n)
- display info gwdInfo ¬
- message ("Folders to go: " & n) at line 5
- end ShowFolderCnt
-
-
- on InfoNew()
- try
- set pref to load preference named kasName
- on error
- set pref to {pfWLoc:{60, 80}}
- end try
-
- set gwdInfo to display info titled kasName ¬
- located at (pfWLoc of pref) ¬
- message ("To: " & kasDst) ¬
- at line 10
- end InfoNew
-
-
- on InfoDel()
- set wLoc to screen location of ¬
- (display info gwdInfo with disposal)
- save preference {pfWLoc:wLoc} named kasName
- end InfoDel
-